- Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSolution.rb
31 lines (28 loc) · 637 Bytes
/
Solution.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Definition for singly-linked list.
# class ListNode
# attr_accessor :val, :next
# def initialize(val = 0, _next = nil)
# @val = val
# @next = _next
# end
# end
# @param {ListNode} list1
# @param {Integer} a
# @param {Integer} b
# @param {ListNode} list2
# @return {ListNode}
defmerge_in_between(list1,a,b,list2)
removed_a=list1
(1...a).eachdo |_|
removed_a=removed_a.next
end
removed_b=removed_a.next
(0..(b - a)).eachdo |_|
removed_b=removed_b.next
end
curr=list2
curr=curr.nextuntilcurr.next.nil?
removed_a.next=list2
curr.next=removed_b
list1
end